import React, {FC, useEffect, useMemo, useState} from 'react'
import {Form, Row, Col, Input, Table} from 'antd'
import {
	getDriverOrderList,
	getDriverillegalList,
} from '@/service/customer/driver'
import styles from './index.less'

interface LeaseLnformationType {
	driverId: string
	leaseLnformationForm: any
	orderList: any[]
	setOrderList: (list: any[]) => void
	illegalList: any[]
	setillegalList: (list: any[]) => void
}

const leaseLnformation: FC<LeaseLnformationType> = ({
	driverId,
	leaseLnformationForm,
	orderList,
	setOrderList,
	illegalList,
	setillegalList,
}) => {
	const [loading, setLoading] = useState(false)
	const [illegalLoading] = useState(false)

	const colnums: any[] = useMemo(
		() => [
			{title: '订单号', dataIndex: 'orderNo', alingn: 'cener'},
			{title: '订单状态', dataIndex: 'status', alingn: 'cener'},
			{title: '订单创建时间', dataIndex: 'createTime', alingn: 'cener'},
			{title: '实际发车时间', dataIndex: 'driverTime', alingn: 'cener'},
			{title: '续租信息', dataIndex: 'continueInfo', alingn: 'cener'},
			{title: '是否延租', dataIndex: 'postpone', alingn: 'cener'},
			{title: '是否个人转租', dataIndex: 'transfer', alingn: 'cener'},
			{
				title: '订单结束是否续租',
				dataIndex: 'orderOverContinueLease',
				alingn: 'cener',
			},
			{title: '续租订单ID', dataIndex: 'leaseNo', alingn: 'cener'},
			{title: '延租类型', dataIndex: 'type', alingn: 'cener'},
			{title: '延租原因', dataIndex: 'reason', alingn: 'cener'},
			{title: '延租时长（天）', dataIndex: 'duration', alingn: 'cener'},
			{title: '延租总天数', dataIndex: 'days', alingn: 'cener'},
			{title: '延租金额', dataIndex: 'money', alingn: 'cener'},
			{title: '免费延租天数', dataIndex: 'freeDays', alingn: 'cener'},
			{title: '收费延租天数', dataIndex: 'feeDays', alingn: 'cener'},
			{title: '免租总天数', dataIndex: 'countFreeDays', alingn: 'cener'},
			{title: '免租总金额', dataIndex: 'countFreeMoney', alingn: 'cener'},
			{title: '租金', dataIndex: 'rental', alingn: 'cener'},
			{title: '服务费', dataIndex: 'serverMoney', alingn: 'cener'},
			{title: '押金', dataIndex: 'deposit', alingn: 'cener'},
			{title: '账单日期', dataIndex: 'billTDate', alingn: 'cener'},
			{title: '欠租金额', dataIndex: 'arrears', alingn: 'cener'},
		],
		[],
	)

	const illegalColnums: any[] = useMemo(
		() => [
			{title: '违章id', dataIndex: 'illegalId', align: 'cener'},
			{title: '违章司机', dataIndex: 'driver', align: 'cener'},
			{title: '城市', dataIndex: 'city', align: 'cener'},
			{title: '车牌号', dataIndex: 'carNo', align: 'cener'},
			{title: '违章说明', dataIndex: 'explain', align: 'cener'},
			{title: '扣分', dataIndex: 'deductMarks', align: 'cener'},
			{title: '罚款', dataIndex: 'fine', align: 'cener'},
			{title: '滞纳金', dataIndex: 'overdueFine', align: 'cener'},
			{title: '所属车队长', dataIndex: 'captain', align: 'cener'},
			{title: '数据来源', dataIndex: 'sourceStr', align: 'cener'},
			{title: '违章状态', dataIndex: 'statusStr', align: 'cener'},
			{title: '时间', dataIndex: 'createDate', align: 'cener'},
			{
				title: '是否司机违章',
				dataIndex: 'driverWringStr',
				align: 'cener',
			},
		],
		[],
	)

	const getList = async () => {
		setLoading(true)
		const data = await getDriverOrderList({driverId}).catch(() => {
			setLoading(false)
		})
		if (data.code === 0) {
			setOrderList([data.data])
			// eslint-disable-next-line no-unused-expressions
			// data.data[0] &&
			leaseLnformationForm.setFieldsValue(
				data.data,
				//   {
				//   leaseStatusStr: data.data[0].leaseStatusStr,
				//   salesTypeStr: data.data[0].salesTypeStr,
				//   listeningEligibilityStr: data.data[0].listeningEligibilityStr,
				//   driverAffiliatedCompanyName: data.data[0].driverAffiliatedCompanyName,
				//   cityName: data.data[0].cityName,
				//   leaseStartDate: data.data[0].leaseStartDate,
				//   leaseEndDate: data.data[0].leaseEndDate,
				//   leaseTerm: data.data[0].leaseTerm,
				//   carNo: data.data[0].carNo,
				//   carModel: data.data[0].carModel,
				//   contractNo: data.data[0].contractNo,
				//   contractStatusStr: data.data[0].contractStatusStr,
				//   driverActivationStatusStr: data.data[0].driverActivationStatusStr,
				//   netSignInitiator: data.data[0].netSignInitiator,
				// }
			)
		}
		setLoading(false)
	}

	const getIllegalList = async () => {
		setLoading(true)
		const data = await getDriverillegalList({driverId}).catch(() => {
			setLoading(false)
		})
		if (data.code === 0) {
			setillegalList(data.data)
		}
		setLoading(false)
	}

	useEffect(() => {
		if (!driverId) return
		if (orderList.length === 0) {
			getList()
		}
		if (illegalList.length === 0) {
			getIllegalList()
		}
	}, [driverId])

	return (
		<div className={styles.leaseLnformation}>
			<div className={styles.titleBox}>当前租凭信息</div>
			<div className={styles.infoBox} style={{padding: '12px 0'}}>
				<Form
					layout="horizontal"
					labelCol={{flex: '140px'}}
					labelAlign="right"
					labelWrap
					autoComplete="off"
					name="CreditInformationFrom"
					form={leaseLnformationForm}
					disabled>
					<Row>
						<Col span={8}>
							<Form.Item name="leaseStatusStr" label="租赁状态">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item name="salesTypeStr" label="销售类型">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="listeningEligibilityStr"
								label="听单资质">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="driverAffiliatedCompanyName"
								label="司机所属公司">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item name="cityName" label="城市">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="leaseStartDate"
								label="租赁开始时间">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item name="leaseEndDate" label="租赁结束时间">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item name="leaseTerm" label="租期">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item name="carNo" label="车牌号">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item name="carModel" label="车型">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item name="contractNo" label="合同号">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="contractStatusStr"
								label="合同审核状态">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="driverActivationStatusStr"
								label="司机激活状态">
								<Input />
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="netSignInitiator"
								label="网签发起人">
								<Input />
							</Form.Item>
						</Col>
						{/* <Col span={8}>
              <Form.Item name="" label="租期">
                <Input />
              </Form.Item>
            </Col> */}
					</Row>
				</Form>
			</div>
			<div className={styles.orderListBox}>
				<div className={styles.titleBoxNoBorder}>当前订单信息</div>
				<Table
					scroll={{x: 2500}}
					rowKey="orderNo"
					dataSource={orderList}
					columns={colnums}
					loading={loading}
				/>
			</div>

			<div className={styles.orderListBox}>
				<div className={styles.titleBoxNoBorder}>当前违章信息</div>
				<Table
					scroll={{x: 1500}}
					rowKey="illegalId"
					dataSource={illegalList}
					columns={illegalColnums}
					loading={illegalLoading}
				/>
			</div>
		</div>
	)
}
export default leaseLnformation
